"""
homework03 - 输入一个英文的句子，统计每个单词出现的次数

Author: Administrator
Date: 2024/1/18
"""

sentence = input('请输入：').lower()
words = sentence.replace(',', '').replace('.', '').replace('!', '').split()

# 循环记录每个单词出现的次数
counter_dict = {}
for word in words:
    # 字典的索引运算如果放在赋值运算符的左边，要么是新增要么是更新
    counter_dict[word] = counter_dict.get(word, 0) + 1
    # if word in counter_dict:
    #     counter_dict[word] += 1
    # else:
    #     counter_dict[word] = 1

# 根据单词出现的次数从高到底排序
sorted_keys = sorted(counter_dict, key=counter_dict.get, reverse=True)
for key in sorted_keys:
    print(f'{key}: {counter_dict[key]}次')